package com.birdboot.test;

import java.util.Arrays;

/**
 * String重载的split方法
 */
public class SplitDemo {
    public static void main(String[] args) {
        String line = "1=2=3=4=5=6=7=========";
        String[] data = line.split("=");
        System.out.println(Arrays.toString(data));
        //limit:2表达拆分出2项
        data = line.split("=",2);
        System.out.println(Arrays.toString(data));
        //limit:3表达拆分出3项
        data = line.split("=",3);
        System.out.println(Arrays.toString(data));
        //当limit>实际可拆分项时,保留所有实际可拆分项(包括最后可能出现的连续的空字符串)
        data = line.split("=",100);
        System.out.println(Arrays.toString(data));

        //当limit=0时,与split(String regex)方法效果一致
        data = line.split("=",0);
        System.out.println(Arrays.toString(data));
        //当limit<0时,表达应拆尽拆,要将所有拆分的内容全部保留
        data = line.split("=",-1);
        System.out.println(Arrays.toString(data));


    }
}
